<template>
  <teleport to="body">
    <header>
      <ul class="menus">
        <li v-for="(item, index) in menusList" :key="index" class="menu-item">
          <router-link :to="item.link">
            <div
              v-animate="'fadeIn'"
              :class="['menu-item-title', item.link === $route.path ? 'active' : '']"
            >
              {{ item.title }}
            </div>
          </router-link>
        </li>

        <li class="menu-item theme-change" @click="toggleTheme">
          <span :class="['btn-circle', appStore.theme]">
            <SvgIcon v-if="appStore.theme === 'dark'" icon-class="icon-sun"></SvgIcon>
            <SvgIcon v-else icon-class="icon-moon"></SvgIcon>
          </span>
        </li>
      </ul>
    </header>
  </teleport>
</template>

<script setup lang="ts">
import { useAppStore } from '@/stores/app';

const appStore = useAppStore();

const menusList = [
  {
    title: 'v-animate',
    link: '/',
    describe: '使用v-animate动画指令实现动画',
  },
  {
    title: 'useAnimateCss',
    link: '/archives',
    describe: '使用useAnimateCss动画钩子实现动画',
  },
  {
    title: 'animateCss',
    link: '/utils',
    describe: '从utils中引入animateCss动画函数实现动画',
  },
];

const toggleTheme = () => {
  const theme = appStore.theme === 'dark' ? 'light' : 'dark';
  appStore.changeTheme(theme);
};
</script>

<style lang="scss" scoped>
header {
  position: absolute;
  top: 0;
  width: 100%;

  .menus {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    height: var(--header-height);
    padding: 10px 16px;
    color: var(--footer-text-color);
    text-align: center;
    background: var(--item-bg-color);
    backdrop-filter: blur(var(--card-filter));

    .menu-item {
      display: flex;
      align-items: center;
      margin: 0 18px;
      font-size: 20px;
      cursor: pointer;

      .menu-item-title {
        font-family: title;
        background-image: var(--gradient);
        background-position: 0%;
        background-clip: text;
        background-size: 200%;

        &.active {
          -webkit-text-fill-color: transparent;
        }
      }

      &.theme-change {
        position: absolute;
        right: 0;
        display: block;
        flex-shrink: 0;
        width: 54px;
        height: 28px;
        background-color: var(--change-theme-btn-bg);
        border: 1px solid var(--change-theme-btn-border);
        border-radius: 14px;
        transition:
          border-color 0.25s,
          background-color 0.25s;

        .btn-circle {
          position: absolute;
          display: flex;
          align-items: center;
          justify-content: center;
          width: 26px;
          height: 26px;
          color: var(--fill);
          background: var(--left-tag-item);
          border-radius: 50%;
          transition:
            background-color 0.25s,
            transform 0.25s;

          &.light {
            transform: translate(1px);
          }

          &.dark {
            transform: translate(26px);
          }
        }
      }
    }
  }
}
</style>
